<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        canvas {
            border: 1px solid black;
            display: block;
            margin: 100px auto;
        }
    </style>
</head>

<body>
    <canvas width="400px" height="400px"></canvas>
</body>

</html>
<script>
    //获取DOM节点
    let canvas = document.querySelector('canvas');
    //获取"笔"
    let ctx = canvas.getContext('2d');

    //绘制线段
    ctx.moveTo(50,350);
    ctx.lineTo(380,350);
    ctx.stroke();

    ctx.font = "20px 微软雅黑";
    //绘制文字:文字内容 x|y
    ctx.fillText('数据可视化',50,50);

    //绘制矩形
    ctx.fillStyle = 'red';
    ctx.fillRect(100,150,50,200);
    //200|50|50|300
    ctx.fillRect(200,50,50,300)
    //300|180|50|170
    ctx.fillRect(300,180,50,170)

</script>